import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

//  商品
export default class HomePrompt extends Component {
  state: any
  props: any
  timer: any
  seconds: number

  constructor() {
    super(...arguments)
    this.state = {
      number: 0
    }
    this.timer = null
    this.seconds = 0
  }

  componentWillMount() {
    this.setTimer(200)
    // const config = getAppletConfig()
  }


  /**
   * 开启倒计时
   */
  setTimer(seconds) {
    this.seconds = seconds
    if (!this.timer) this.countdown()
  }

  /**
   * 倒计时
   */
  countdown() {
    if (this.seconds === undefined) {
      return;
    }

    this.timer = setInterval(() => {
      console.log(0)
      this.seconds++
    }, 10)
  }

  /**
   * 清除计时器
   */
  clearTimer() {
    if (this.timer) {
      clearInterval(this.timer)
      this.timer = undefined
    }
  }

  render() {
    return (
      <View style={{color: '#fff'}}>
        组件{this.seconds}
      </View>
    )
  }
}
